<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin pro - 通用后台管理模板系统（单页面专业版）</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/admin/css/style.css">
    <script src="__STATIC__/lib/layui/layui.js" ></script>
    <script src="__STATIC__/admin/js/jquery-3.3.1.js"></script>
    <link id="layuicss-layuiAdmin" rel="stylesheet" href="__STATIC__/admin/css/admin.css" media="all">
</head>
<body layadmin-themealias="default" class="layui-layout-body" style="">
<div id="LAY_app" class="layadmin-tabspage-none">
    <div class="layui-layout layui-layout-admin">
        <!--头部文件-->
        {include file="common/header"/}
        <!--左侧导航栏-->
        {include file="common/left"/}

        <!-- 主体内容 -->
        <div class="layui-body" id="LAY_app_body">
            <div class="layadmin-tabsbody-item layui-show">
                <div class="layui-card layadmin-header">
                    <div class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
                        <a lay-href="{:url('index/index')}">主页</a><span lay-separator="">/</span>
                        <a href="{:url('lst')}"><cite>权限管理</cite></a><span lay-separator="">/</span>
                        <a><cite>添加权限</cite></a>
                    </div>
                </div>


                <div class="layui-fluid">
                    <div class="layui-card" style="padding-bottom: 20px;padding-top: 20px;">
                        <form class="layui-form" method="post">

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">所属权限</label>
                                <div class="layui-input-inline">
                                    <select name="pid" id="">
                                        <option value="0">顶级权限</option>
                                        {foreach $powerL as $key=>$vo}
                                            <option value="{$vo['id']}"> <?php  if($vo['level']!=0){ echo '|'.str_repeat('----',$vo['level']);} else{ echo str_repeat('----',$vo['level']);}  ?> {$vo['name']}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>

                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">权限名称</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="name" lay-verify="required|name" autocomplete="off" class="layui-input" value="管理员">
                                </div>
                            </div>

                        </div>

                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">权限链接</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="url" lay-verify="" placeholder="" autocomplete="off" class="layui-input" value="">
                                </div>
                                <div class="layui-form-mid layui-word-aux">顶级域名可为空，其他格式为：Admin/lst</div>
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">管理状态</label>
                            <div class="layui-input-block">
                                <input type="checkbox" checked="" name="status" lay-skin="switch" lay-filter="switchTest" lay-text="开启|锁定">
                                <div class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch">
                                    <em>ON</em>
                                    <i></i>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sub">提交</button>
                                <a class="layui-btn layui-btn-primary" href="{:url('lst')}">返回</a>
                            </div>
                        </div>

                    </form>
                    </div>


                </div>

            </div>
        </div>


    </div>
</div>


</body>

<script>
    $(function () {
        layui.use('form',function (data) {
            var form=layui.form; var layer=layui.layer;
            form.render();  //下拉框弹出
            form.on("submit(sub)",function (data) {
                //设置状态
                if(data.field.status=='on'){
                    data.field.status='1';
                }else {
                    data.field.status='0';
                }

                if(data.field.pid!=0 && data.field.url==''){
                    layer.msg('只有顶级栏目才能为空');
                    return false;
                }

                //提交数据
                $.post("{:url('power/add')}",data.field,function (res) {
                    if(res.code==1){
                        layer.msg(res.msg,{icon:1,time:1800});
                        setTimeout(function () {
                            window.location.href="{:url('lst')}";
                        },1500);
                    }else {
                        layer.msg(res.msg,{icon:5,time:1800});
                    }

                    return false;
                });

                return false;
            });

        });
    });



</script>


</html>